package com.ysd.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ysd.dao.Impl.ChanPinXiLieDaoImpl;
import com.ysd.dao.Impl.ProductCatalogueDaoImpl;
import com.ysd.dao.Impl.ProductDaoImpl;
import com.ysd.entity.Product;
import com.ysd.entity.ProductCatalogue;

public class ProductsServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//产品分类
		ProductCatalogueDaoImpl pDao=new ProductCatalogueDaoImpl();
		List<ProductCatalogue> pclist=pDao.getPCList();
		request.setAttribute("pclist", pclist);
		
		//根据产品分类id查询对应产品
		//接收前台传来的参数(转型int)
		int cId=Integer.parseInt(request.getParameter("productCatalogueId"));
		ProductDaoImpl prDao=new ProductDaoImpl();
		List<Product> productList=prDao.getProductsList(cId);
		request.setAttribute("productList", productList);
		//调用产品系列的实现类
		int pId=Integer.parseInt(request.getParameter("productCatalogueId"));
		ChanPinXiLieDaoImpl  xlDao=new ChanPinXiLieDaoImpl();
		List<ProductCatalogue> xlList=xlDao.getChanPinXiLieList(pId);
		request.setAttribute("xlList", xlList);
		
		request.getRequestDispatcher("productlist.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
